package com.bee.beeAuth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;


/**
 * @description:
 * @author: chenguosong
 * @date: 2022-12-02 09:49
 */
@Configuration
public class ResourceConfigService extends ResourceServerConfigurerAdapter {
    //资源服务的id
    public static final String RESOURCE_ID = "beeLove";

    @Bean
    public ResourceServerTokenServices resourceServerTokenServices(){
        RemoteTokenServices remoteTokenServices = new RemoteTokenServices();
        remoteTokenServices.setCheckTokenEndpointUrl("http://127.0.0.1:8089/oauth/check_token");
        remoteTokenServices.setClientId("test");
        remoteTokenServices.setClientSecret("test");
        return remoteTokenServices;
    }


    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        resources.resourceId(RESOURCE_ID).tokenServices(resourceServerTokenServices()).stateless(true);
    }

}
